package com.wudeyong;

import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * Author :wudeyong
 * Date 2017/6/21
 * For More Information,Please Visit https://wudeyong.com
 */
public class APriori {
//    数据集
    private List<String > [] dataset;
//    名称映射，商品编号映射到具体名字
    private String[] nameMapper;

    HashMap<String,boolean[]> data;

    private int support;

    public static  void main(String args[]){
        APriori apriori=new APriori();
        System.out.println("请输入文件的路径：");
        Scanner scanner =new Scanner(System.in);
        String filePath=scanner.nextLine();
        apriori.getDataFromFile(filePath);
    }

    public void getDataFromFile(String filePath){
        File file=new File(filePath);
        try {
            InputStreamReader reader=new InputStreamReader(new FileInputStream(file));
            BufferedReader bufferedReader=new BufferedReader(reader);
            String tmp;

            data=new HashMap<String, boolean[]>();
            tmp=bufferedReader.readLine();
            nameMapper=tmp.split("  ");
            while((tmp=bufferedReader.readLine())!=null){
                String tmpArray[]=tmp.split("   ");
                boolean isTrue[]=new boolean[tmpArray.length-1];
                int i=0;
                for(i=0;i<isTrue.length-1;i++);
                {
                    isTrue[i - 1] = tmpArray[i].equals("T");
                }
                data.put(tmpArray[0],isTrue);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int[] find_frequent_1_itemsets(HashMap<String,boolean[]> dataSet,int threshold){


        int itemsNumber=nameMapper.length;
        int[] itemSets=new int[itemsNumber];
//        String [][]itemSets=new String[itemsNumber][2];
//        for(int i=0;i<nameMapper.length;i++)
//            itemSets[i][0]=nameMapper[i];
        for(String key:dataSet.keySet()){
            boolean result[]=dataSet.get(key);
            for (int i=0;i<result.length;i++){
                if(result[i]){
                    itemSets[i]+=1;
                }
            }
        }
        for(int i=0;i<itemSets.length;i++){
            if (itemSets[i]<threshold)
                itemSets[i]=0;
        }

        return itemSets;
    }

    public void findL(){
//        String[][] L1 =find_frequent_1_itemsets(data,1);
//        for(int k=2;)
        int[][] kSets=new int[100][200];
        kSets[1]=find_frequent_1_itemsets(data,1);
        boolean resultK=false;
        for(int i=0;i<kSets[1].length;i++){
            if(kSets[1][i]>1){
                resultK=true;
                break;
            }
            else resultK=false;
        }
        for(int k=2;resultK;k++){

        }
    }

    public void a_priori_gen(){

    }

    public void find_2_squence(int[] dataSet){
        for(int i=0;i<dataSet.length;i++){
            for(int j=i+1;j<dataSet.length;j++){

            }
        }

    }
}
